home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / dom / nsPIDOMWindow.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  11KB  |  396 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set ts=2 sw=2 et tw=80: */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  27.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39.  
  40. #ifndef nsPIDOMWindow_h__
  41. #define nsPIDOMWindow_h__
  42.  
  43. #include "nsISupports.h"
  44. #include "nsIDOMLocation.h"
  45. #include "nsIDOMXULCommandDispatcher.h"
  46. #include "nsIDOMElement.h"
  47. #include "nsIDOMWindowInternal.h"
  48. #include "nsIChromeEventHandler.h"
  49. #include "nsIDOMDocument.h"
  50. #include "nsIURI.h"
  51. #include "nsCOMPtr.h"
  52.  
  53. // Popup control state enum. The values in this enum must go from most
  54. // permissive to least permissive so that it's safe to push state in
  55. // all situations. Pushing popup state onto the stack never makes the
  56. // current popup state less permissive (see
  57. // nsGlobalWindow::PushPopupControlState()).
  58. enum PopupControlState {
  59.   openAllowed = 0,  // open that window without worries
  60.   openControlled,   // it's a popup, but allow it
  61.   openAbused,       // it's a popup. disallow it, but allow domain override.
  62.   openOverridden    // disallow window open
  63. };
  64.  
  65. // permissible values for GetOpenAllow
  66. enum OpenAllowValue {
  67.   allowNot = 0,     // the window opening is denied
  68.   allowNoAbuse,     // allowed: not a popup
  69.   allowSelf,        // allowed: it's the same window (_self, _top, et.al.)
  70.   allowExtant,      // allowed: an already open window
  71.   allowWhitelisted  // allowed: it's whitelisted or popup blocking is disabled
  72. };
  73.  
  74. class nsIDocShell;
  75. class nsIFocusController;
  76. class nsIDocument;
  77. struct nsTimeout;
  78.  
  79. #define NS_PIDOMWINDOW_IID \
  80. { 0x55f987bc, 0xca30, 0x494c, \
  81.   { 0xa9, 0x85, 0xf1, 0xf3, 0x4b, 0x9d, 0x47, 0xd8 } }
  82.  
  83. class nsPIDOMWindow : public nsIDOMWindowInternal
  84. {
  85. public:
  86.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOW_IID)
  87.  
  88.   virtual nsPIDOMWindow* GetPrivateRoot() = 0;
  89.  
  90.   virtual nsresult GetObjectProperty(const PRUnichar* aProperty,
  91.                                      nsISupports** aObject) = 0;
  92.  
  93.   // This is private because activate/deactivate events are not part
  94.   // of the DOM spec.
  95.   virtual nsresult Activate() = 0;
  96.   virtual nsresult Deactivate() = 0;
  97.  
  98.   nsIChromeEventHandler* GetChromeEventHandler() const
  99.   {
  100.     return mChromeEventHandler;
  101.   }
  102.  
  103.   PRBool HasMutationListeners(PRUint32 aMutationEventType) const
  104.   {
  105.     const nsPIDOMWindow *win;
  106.  
  107.     if (IsOuterWindow()) {
  108.       win = GetCurrentInnerWindow();
  109.  
  110.       if (!win) {
  111.         NS_ERROR("No current inner window available!");
  112.  
  113.         return PR_FALSE;
  114.       }
  115.     } else {
  116.       if (!mOuterWindow) {
  117.         NS_ERROR("HasMutationListeners() called on orphan inner window!");
  118.  
  119.         return PR_FALSE;
  120.       }
  121.  
  122.       win = this;
  123.     }
  124.  
  125.     return (win->mMutationBits & aMutationEventType) != 0;
  126.   }
  127.  
  128.   void SetMutationListeners(PRUint32 aType)
  129.   {
  130.     nsPIDOMWindow *win;
  131.  
  132.     if (IsOuterWindow()) {
  133.       win = GetCurrentInnerWindow();
  134.  
  135.       if (!win) {
  136.         NS_ERROR("No inner window available to set mutation bits on!");
  137.  
  138.         return;
  139.       }
  140.     } else {
  141.       if (!mOuterWindow) {
  142.         NS_ERROR("HasMutationListeners() called on orphan inner window!");
  143.  
  144.         return;
  145.       }
  146.  
  147.       win = this;
  148.     }
  149.  
  150.     win->mMutationBits |= aType;
  151.   }
  152.  
  153.   virtual nsIFocusController* GetRootFocusController() = 0;
  154.  
  155.   // GetExtantDocument provides a backdoor to the DOM GetDocument accessor
  156.   nsIDOMDocument* GetExtantDocument() const
  157.   {
  158.     return mDocument;
  159.   }
  160.  
  161.   // Internal getter/setter for the frame element, this version of the
  162.   // getter crosses chrome boundaries whereas the public scriptable
  163.   // one doesn't for security reasons.
  164.   nsIDOMElement* GetFrameElementInternal() const
  165.   {
  166.     if (mOuterWindow) {
  167.       return mOuterWindow->GetFrameElementInternal();
  168.     }
  169.  
  170.     NS_ASSERTION(!IsInnerWindow(),
  171.                  "GetFrameElementInternal() called on orphan inner window");
  172.  
  173.     return mFrameElement;
  174.   }
  175.  
  176.   void SetFrameElementInternal(nsIDOMElement *aFrameElement)
  177.   {
  178.     if (IsOuterWindow()) {
  179.       mFrameElement = aFrameElement;
  180.  
  181.       return;
  182.     }
  183.  
  184.     if (!mOuterWindow) {
  185.       NS_ERROR("frameElement set on inner window with no outer!");
  186.  
  187.       return;
  188.     }
  189.  
  190.     mOuterWindow->SetFrameElementInternal(aFrameElement);
  191.   }
  192.  
  193.   PRBool IsLoadingOrRunningTimeout() const
  194.   {
  195.     const nsPIDOMWindow *win = GetCurrentInnerWindow();
  196.  
  197.     if (!win) {
  198.       win = this;
  199.     }
  200.  
  201.     return !win->mIsDocumentLoaded || win->mRunningTimeout;
  202.   }
  203.  
  204.   // Check whether a document is currently loading
  205.   PRBool IsLoading() const
  206.   {
  207.     const nsPIDOMWindow *win;
  208.  
  209.     if (IsOuterWindow()) {
  210.       win = GetCurrentInnerWindow();
  211.  
  212.       if (!win) {
  213.         NS_ERROR("No current inner window available!");
  214.  
  215.         return PR_FALSE;
  216.       }
  217.     } else {
  218.       if (!mOuterWindow) {
  219.         NS_ERROR("IsLoading() called on orphan inner window!");
  220.  
  221.         return PR_FALSE;
  222.       }
  223.  
  224.       win = this;
  225.     }
  226.  
  227.     return !win->mIsDocumentLoaded;
  228.   }
  229.  
  230.   PRBool IsHandlingResizeEvent() const
  231.   {
  232.     const nsPIDOMWindow *win;
  233.  
  234.     if (IsOuterWindow()) {
  235.       win = GetCurrentInnerWindow();
  236.  
  237.       if (!win) {
  238.         NS_ERROR("No current inner window available!");
  239.  
  240.         return PR_FALSE;
  241.       }
  242.     } else {
  243.       if (!mOuterWindow) {
  244.         NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!");
  245.  
  246.         return PR_FALSE;
  247.       }
  248.  
  249.       win = this;
  250.     }
  251.  
  252.     return win->mIsHandlingResizeEvent;
  253.   }
  254.  
  255.   virtual void SetOpenerScriptURL(nsIURI* aURI) = 0;
  256.  
  257.   virtual PopupControlState PushPopupControlState(PopupControlState aState,
  258.                                                   PRBool aForce) const = 0;
  259.   virtual void PopPopupControlState(PopupControlState state) const = 0;
  260.   virtual PopupControlState GetPopupControlState() const = 0;
  261.   virtual OpenAllowValue GetOpenAllow(const nsAString &aName) = 0;
  262.  
  263.   // Returns an object containing the window's state.  This also suspends
  264.   // all running timeouts in the window.
  265.   virtual nsresult SaveWindowState(nsISupports **aState) = 0;
  266.  
  267.   // Restore the window state from aState.
  268.   virtual nsresult RestoreWindowState(nsISupports *aState) = 0;
  269.  
  270.   // Resume suspended timeouts in this window and in child windows.
  271.   virtual nsresult ResumeTimeouts() = 0;
  272.  
  273.   nsPIDOMWindow *GetOuterWindow()
  274.   {
  275.     return mIsInnerWindow ? mOuterWindow : this;
  276.   }
  277.  
  278.   nsPIDOMWindow *GetCurrentInnerWindow() const
  279.   {
  280.     return mInnerWindow;
  281.   }
  282.  
  283.   PRBool IsInnerWindow() const
  284.   {
  285.     return mIsInnerWindow;
  286.   }
  287.  
  288.   PRBool IsOuterWindow() const
  289.   {
  290.     return !IsInnerWindow();
  291.   }
  292.  
  293.   virtual PRBool WouldReuseInnerWindow(nsIDocument *aNewDocument) = 0;
  294.  
  295. protected:
  296.   // The nsPIDOMWindow constructor. The aOuterWindow argument should
  297.   // be null if and only if the created window itself is an outer
  298.   // window. In all other cases aOuterWindow should be the outer
  299.   // window for the inner window that is being created.
  300.   nsPIDOMWindow(nsPIDOMWindow *aOuterWindow)
  301.     : mFrameElement(nsnull), mRunningTimeout(nsnull), mMutationBits(0),
  302.       mIsDocumentLoaded(PR_FALSE), mIsHandlingResizeEvent(PR_FALSE),
  303.       mIsInnerWindow(aOuterWindow != nsnull), mInnerWindow(nsnull),
  304.       mOuterWindow(aOuterWindow)
  305.   {
  306.   }
  307.  
  308.   // These two variables are special in that they're set to the same
  309.   // value on both the outer window and the current inner window. Make
  310.   // sure you keep them in sync!
  311.   nsCOMPtr<nsIChromeEventHandler> mChromeEventHandler; // strong
  312.   nsCOMPtr<nsIDOMDocument> mDocument; // strong
  313.  
  314.   // These members are only used on outer windows.
  315.   nsIDOMElement *mFrameElement; // weak
  316.   nsCOMPtr<nsIURI> mOpenerScriptURL; // strong; used to determine whether to clear scope
  317.  
  318.   // These variables are only used on inner windows.
  319.   nsTimeout             *mRunningTimeout;
  320.  
  321.   PRUint32               mMutationBits;
  322.  
  323.   PRPackedBool           mIsDocumentLoaded;
  324.   PRPackedBool           mIsHandlingResizeEvent;
  325.   PRPackedBool           mIsInnerWindow;
  326.  
  327.   // And these are the references between inner and outer windows.
  328.   nsPIDOMWindow         *mInnerWindow;
  329.   nsPIDOMWindow         *mOuterWindow;
  330. };
  331.  
  332.  
  333. #ifdef _IMPL_NS_LAYOUT
  334. PopupControlState
  335. PushPopupControlState(PopupControlState aState, PRBool aForce);
  336.  
  337. void
  338. PopPopupControlState(PopupControlState aState);
  339.  
  340. #define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherInternal
  341. #else
  342. #define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherExternal
  343. #endif
  344.  
  345. // Helper class that helps with pushing and popping popup control
  346. // state. Note that this class looks different from within code that's
  347. // part of the layout library than it does in code outside the layout
  348. // library.  We give the two object layouts different names so the symbols
  349. // don't conflict, but code should always use the name
  350. // |nsAutoPopupStatePusher|.
  351. class NS_AUTO_POPUP_STATE_PUSHER
  352. {
  353. public:
  354. #ifdef _IMPL_NS_LAYOUT
  355.   NS_AUTO_POPUP_STATE_PUSHER(PopupControlState aState, PRBool aForce = PR_FALSE)
  356.     : mOldState(::PushPopupControlState(aState, aForce))
  357.   {
  358.   }
  359.  
  360.   ~NS_AUTO_POPUP_STATE_PUSHER()
  361.   {
  362.     PopPopupControlState(mOldState);
  363.   }
  364. #else
  365.   NS_AUTO_POPUP_STATE_PUSHER(nsPIDOMWindow *aWindow, PopupControlState aState)
  366.     : mWindow(aWindow), mOldState(openAbused)
  367.   {
  368.     if (aWindow) {
  369.       mOldState = aWindow->PushPopupControlState(aState, PR_FALSE);
  370.     }
  371.   }
  372.  
  373.   ~NS_AUTO_POPUP_STATE_PUSHER()
  374.   {
  375.     if (mWindow) {
  376.       mWindow->PopPopupControlState(mOldState);
  377.     }
  378.   }
  379. #endif
  380.  
  381. protected:
  382. #ifndef _IMPL_NS_LAYOUT
  383.   nsCOMPtr<nsPIDOMWindow> mWindow;
  384. #endif
  385.   PopupControlState mOldState;
  386.  
  387. private:
  388.   // Hide so that this class can only be stack-allocated
  389.   static void* operator new(size_t /*size*/) CPP_THROW_NEW { return nsnull; }
  390.   static void operator delete(void* /*memory*/) {}
  391. };
  392.  
  393. #define nsAutoPopupStatePusher NS_AUTO_POPUP_STATE_PUSHER
  394.  
  395. #endif // nsPIDOMWindow_h__
  396.